package org.springblade.modules.restaurant.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.model.ExecuteResult;
import com.aizuda.snailjob.common.log.SnailJobLog;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.restaurant.service.IUserSalaryDayService;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 用户日薪表生成任务
 *
 * @author harry
 * @公众号 Harry技术
 */
@Slf4j
@Component
@AllArgsConstructor
@JobExecutor(name = "userSalaryDayJobExecutor")
public class UserSalaryDayJobExecutor {
	private final IUserSalaryDayService userSalaryDayService;

	public ExecuteResult jobExecute(JobArgs jobArgs) {
		SnailJobLog.REMOTE.info("用户日薪表生成任务,jobArgs:{}", jobArgs);

		Date date = DateUtil.date();
		// 获取开始时间
		DateTime startTime = DateUtil.beginOfDay(date);
		// 获取当前时间
		DateTime endTime = DateUtil.endOfDay(date);
		userSalaryDayService.gen(startTime, endTime);
		return ExecuteResult.success();
	}


//	@PostConstruct
	public void init() {
		log.info("用户日薪表生成任务启动");
		for (int i = 0; i < 25; i++) {
			Date date = DateUtil.offsetDay(DateUtil.date(), -(24 - i));

			// 获取开始时间
			DateTime startTime = DateUtil.beginOfDay(date);
			// 获取当前时间
			DateTime endTime = DateUtil.endOfDay(date);
			userSalaryDayService.gen(startTime, endTime);
		}
	}
}
